//
//  FlipsideViewController.m
//  AppSettings
//
//  Created by KaiKai on 11-8-13.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MainViewController.h"
#import "FlipsideViewController.h"

@implementation FlipsideViewController

@synthesize delegate = _delegate;
@synthesize engineSwitch;
@synthesize warpFactorSlider;

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];  
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	engineSwitch.on = [[defaults objectForKey:KWarpDriveKey] isEqualToString:@"Value for On"] ? YES : NO;
	warpFactorSlider.value = [defaults floatForKey:KWarpFactorKey];
}

- (void)viewWillDisappear:(BOOL)animated
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	NSString *prefValue = (engineSwitch.on) ? @"Value for On" : @"Value for Off";
	[defaults setObject:prefValue forKey:KWarpDriveKey];
	[defaults setFloat:warpFactorSlider.value forKey:KWarpFactorKey];
	
	[super viewWillDisappear:animated];
}

- (void)dealloc
{
	[engineSwitch release];
	[warpFactorSlider release];
	
	[super dealloc];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Actions

- (IBAction)done:(id)sender
{
    [self.delegate flipsideViewControllerDidFinish:self];
}

@end
